package task1

import org.apache.flink.api.scala.createTypeInformation
import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment}

/**
 * @author jhhe66
 * @date 2021/6/17 20:25
 */
object WordCountScalaStream {
  def main(args: Array[String]): Unit = {
    // 获取流环境
    val env = StreamExecutionEnvironment.getExecutionEnvironment

    // 连接socket
    val socketDS: DataStream[String] = env.socketTextStream("centos01", 9999);
    val res: DataStream[(String, Int)] = socketDS.flatMap(_.split("\\s+"))
      .map((_, 1))
      .keyBy(_._1)
      .sum(1)

    res.print()
    env.execute()
  }
}
